﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using RoccaStore.Data;
using RoccaStore.Utils;

namespace RoccaStore.Services
{
    public class AccountService : ServiceBase<IAccountRepository>, IAccountService
    {
        public Account GetByID(int id)
        {
            return Repository.GetByID(id);
        }

        public Account GetByEmail(string email)
        {
            return Repository.GetByEmail(email);
        }

        public Account GetByFacebookID(string facebookId)
        {
            return Repository.GetByFacebookID(facebookId);
        }

        public List<Account> GetAll()
        {
            return Repository.GetAll();
        }

        public int Save(Account account)
        {
            return Repository.Save(account);
        }

        public void Authorize(Account account)
        {
            Current = account;
        }

        public Account Current
        {
            get
            {
                if (HttpContext.Current.Session["CurrentAccount"] != null)
                    return (Account)HttpContext.Current.Session["CurrentAccount"];

                return null;
            }
            set
            {
                HttpContext.Current.Session["CurrentAccount"] = value;
            }
        }

        public void Logout()
        {
            HttpContext.Current.Session["CurrentAccount"] = null;
        }
    }
}
